package com.bot.nft.module.op.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bot.auth.core.pojo.SaBaseLoginUser;
import com.bot.auth.core.util.StpLoginUserUtil;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.core.enums.op.AirdropEnum;
import com.bot.nft.module.op.domain.bo.OpAirInfoBo;
import com.bot.nft.module.op.domain.bo.OpAirInfoQueryBo;
import com.bot.nft.module.op.domain.bo.OpAirLogQueryBo;
import com.bot.nft.module.op.domain.vo.OpAirExeLogVo;
import com.bot.nft.module.op.domain.vo.OpAirInfoVo;
import com.bot.nft.module.op.domain.vo.OpAirLogVo;
import com.bot.nft.module.op.service.IOpAirInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 空投活动前端控制器
 * </p>
 *
 * @author zhangkaige
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/air")
public class OpAirInfoController {
    @Resource
    IOpAirInfoService airInfoService;

    //添加空投信息
    @PostMapping("/addAirInfo.do")
    public CommonResult<String> addAirInfo(@RequestBody @Valid OpAirInfoBo airInfoBo) {
        //获取用户信息
        SaBaseLoginUser loginUser = StpLoginUserUtil.getLoginUser();
        //封装信息
        airInfoBo.setStatus(AirdropEnum.DISABLE_STATUS.getValue());
        airInfoBo.setCreateUser(loginUser.getName());
        airInfoBo.setCreateTime(new Date());
        airInfoBo.setDeleteFlag(AirdropEnum.DELETE.getValue());
        Boolean flag = airInfoService.addAirInfo(airInfoBo);

        return flag ? CommonResult.ok() : CommonResult.error();
    }

    //执行空投活动
    @GetMapping("/{airId}/exeAirdrop.do")
    public CommonResult<Boolean> exeAirdrop(@PathVariable String airId) {
        Boolean flag = airInfoService.exeAirdrop(airId);

        return flag ? CommonResult.ok() : CommonResult.error();
    }

    //删除空投活动
    @GetMapping("/{airId}/deleteAirdrop.do")
    public CommonResult<Boolean> deleteAirdrop(@PathVariable String airId) {
        Boolean flag = airInfoService.deleteAirdrop(airId);

        return flag ? CommonResult.ok() : CommonResult.error();
    }

    //分页查询空投信息
    @PostMapping("/{pageNo}/{pageSize}/pageAirInfo.do")
    public CommonResult<Page<OpAirInfoVo>> pageAirInfo(@PathVariable Integer pageNo,
                                                       @PathVariable Integer pageSize,
                                                       @RequestBody OpAirInfoQueryBo airQueryBo) {
        Page<OpAirInfoVo> airInfoVoPage = airInfoService.pageAirInfo(pageNo, pageSize, airQueryBo.getAirName(),
                airQueryBo.getConType(), airQueryBo.getStatus());
        return CommonResult.data(airInfoVoPage);

    }

    //查看空投信息
    @GetMapping("/{airId}/getAirInfo.do")
    public CommonResult<OpAirInfoVo> getAirInfo(@PathVariable String airId) {
        OpAirInfoVo airInfoVo = airInfoService.getAirInfo(airId);
        return CommonResult.data(airInfoVo);
    }

    //更新空投信息
    @PostMapping("/updateAirInfo.do")
    public CommonResult<String> updateAirInfo(@RequestBody @Valid OpAirInfoBo airInfoBo) {
        //获取用户信息
        SaBaseLoginUser loginUser = StpLoginUserUtil.getLoginUser();
        //封装信息
        airInfoBo.setStatus(AirdropEnum.DISABLE_STATUS.getValue());
        airInfoBo.setUpdateUser(loginUser.getName());
        airInfoBo.setUpdateTime(new Date());
        airInfoBo.setDeleteFlag(AirdropEnum.DELETE.getValue());
        Boolean flag = airInfoService.updateAirInfo(airInfoBo);

        return flag ? CommonResult.ok() : CommonResult.error();
    }

    //启用空投活动
    @GetMapping("/{airId}/enableAirInfo.do")
    public CommonResult<String> enableAirInfo(@PathVariable String airId) {
        Boolean flag = airInfoService.enableAirInfo(airId);

        return flag ? CommonResult.ok() : CommonResult.error();
    }

    //停用空投活动
    @GetMapping("/{airId}/disableAirInfo.do")
    public CommonResult<String> disableAirInfo(@PathVariable String airId) {
        Boolean flag = airInfoService.disableAirInfo(airId);

        return flag ? CommonResult.ok() : CommonResult.error();
    }

    //分页查询空投记录
    @PostMapping("/{pageNo}/{pageSize}/pageAirLog.do")
    public CommonResult<Page<OpAirLogVo>> pageAirLog(@RequestBody OpAirLogQueryBo airLogQueryBo,
                                                     @PathVariable Integer pageNo,
                                                     @PathVariable Integer pageSize) {
        Page<OpAirLogVo> airLogVos = airInfoService.pageAirLog(pageNo, pageSize, airLogQueryBo.getAirId(),
                airLogQueryBo.getPhoneKeyword());
        return CommonResult.data(airLogVos);
    }

    //查询空投执行记录
    @GetMapping("/{airId}/getAirExeLogList.do")
    public CommonResult<List<OpAirExeLogVo>> getAirExeLogList(@PathVariable String airId) {
        List<OpAirExeLogVo> airExeLogVos = airInfoService.getAirExeLogList(airId);
        return CommonResult.data(airExeLogVos);
    }

}
